package com.fengye.algorithms.leecode;

import com.fengye.algorithms.leecode.common.TreeNode;

/**
 * @Author fengye
 * @Date 2023/4/19 9:23
 **/
public class SearchInABinarySearchTree700 {

    public TreeNode searchBST(TreeNode root, int val) {
        if(root == null) {
            return null;
        }

        if(root.val == val) {
            return root;
        }
        // root.val小于val,说明在右树
        if(root.val < val) {
            return searchBST(root.right, val);
        }
        // 否则在左树
        return searchBST(root.left, val);
    }
}
